// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package errchk

import (
	"os/exec"
	"runtime"
)

var bin, binErr = exec.LookPath(runtime.GOROOT() + "/test/errchk")

// Run invokes the errchk tool with given args, returns the CombinedOutput and
// an error if any.
func Run(args ...string) (out []byte, err error) {
	if err = binErr; err != nil {
		return
	}
	return exec.Command(bin, args...).CombinedOutput()
}

// Must panics if the errchk tool was not found using os/exec.LookPath.
func Must() {
	if binErr != nil {
		panic(binErr)
	}
}
